//
//  keyboardToolBar.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/8/10.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "keyboardToolBar.h"

@interface keyboardToolBar ()
@property (nonatomic,weak)UIButton *emotionBUtton;

@end

@implementation keyboardToolBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor blackColor];
        _importText = [[UITextField alloc] init];
        [_importText setReturnKeyType:UIReturnKeyDone];
        CGFloat textY = frame.size.height * 0.2;
        CGFloat textH = frame.size.height * 0.6;
        CGFloat textX = frame.size.width * 0.025;
        CGFloat textW = frame.size.width * 0.725;
        _importText.frame = CGRectMake(textX, textY, textW, textH);
        _importText.backgroundColor = [UIColor whiteColor];
        _importText.borderStyle = UITextBorderStyleRoundedRect;
        _importText.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_importText];
        
        CGFloat buttonW = textH;
        CGFloat buttonGap = (frame.size.width * 0.25 - buttonW * 2) / 3;
        CGFloat buttonX = CGRectGetMaxX(_importText.frame) + buttonGap;
        CGFloat button2X = frame.size.width - buttonGap - buttonW;
        CGFloat buttonY = 0.5*frame.size.height - buttonW / 2;
        [self addButtonWithIcon:@"duiHao" tag:BPkeyboardToolBarButtonTypeSend buttonFrame:CGRectMake(buttonX, buttonY, buttonW, buttonW)];
        self.emotionBUtton = [self addButtonWithIcon:@"keyBoardW" tag:BPkeyboardToolBarButtonTypeText buttonFrame:CGRectMake(button2X, buttonY, buttonW, buttonW)];
    }
    return self;
}

- (void)setShowTextStyle:(BOOL)ShowTextStyle
{
    if (ShowTextStyle) {
        //显示字体按钮
        [self.emotionBUtton setImage:[UIImage imageNamed:@"textStyle"] forState:UIControlStateNormal];
    }else{
        [self.emotionBUtton setImage:[UIImage imageNamed:@"keyBoardW"] forState:UIControlStateNormal];
    }
}

- (UIButton *)addButtonWithIcon:(NSString *)icon tag:(BPkeyboardToolBarButtonType)tag buttonFrame:(CGRect)buttonFrame
{
    UIButton *button = [[UIButton alloc] init];
    button.tag = tag;
    button.frame = buttonFrame;
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
    [self addSubview:button];
    return button;
}

- (void)buttonClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(keyboardTool:didClickedButton:)]) {
        [self.delegate keyboardTool:self didClickedButton:button.tag];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
